/*
 * @文件描述: 多功能仪表的主界面，并负责显示一些通用的东西
 * @版本: 
 * @作者: 周晨阳
 * @Date: 2021-02-23 16:36:41
 */
#ifdef GUI_UCGUI

#include "mainPageUICodes.h"

//EventsFunctionList
void OnMultiMeterClicked(WM_MESSAGE *pMsg);
void OnOscillClicked(WM_MESSAGE *pMsg);
//EndofEventsFunctionList

/*********************************************************************
*
*       static data
*
**********************************************************************
*/

/*********************************************************************
*
*       Dialog resource
*
* This table conatins the info required to create the dialog.
* It has been created by ucGUIbuilder.
*/

static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    {FRAMEWIN_CreateIndirect, "multiMeter&oscill", 0, 0, 0, 854, 480, FRAMEWIN_CF_MOVEABLE, 0},
    {BUTTON_CreateIndirect, "Oscill", GUI_ID_BUTTON0, 38, 126, 160, 160, 0, 0},
    {BUTTON_CreateIndirect, "MultiMeter", GUI_ID_BUTTON1, 290, 126, 160, 160, 0, 0},
    {BUTTON_CreateIndirect, "Setting", GUI_ID_BUTTON2, 525, 126, 160, 160, 0, 0}};

/*****************************************************************
**      FunctionName:void PaintDialog(WM_MESSAGE * pMsg)
**      Function: to initialize the Dialog items
**                                                      
**      call this function in _cbCallback --> WM_PAINT
*****************************************************************/

static void PaintDialog(WM_MESSAGE *pMsg)
{
    WM_HWIN hWin = pMsg->hWin;
}

/*****************************************************************
**      FunctionName:void InitDialog(WM_MESSAGE * pMsg)
**      Function: to initialize the Dialog items
**                                                      
**      call this function in _cbCallback --> WM_INIT_DIALOG
*****************************************************************/

static void InitDialog(WM_MESSAGE *pMsg)
{
    WM_HWIN hWin = pMsg->hWin;
    //
    //FRAMEWIN
    //
    FRAMEWIN_SetFont(hWin, &GUI_Font24_ASCII);
    FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
    FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
    FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
    FRAMEWIN_SetTitleHeight(hWin, 24);
    //
    //GUI_ID_BUTTON0
    //
    BUTTON_SetFont(WM_GetDialogItem(hWin, GUI_ID_BUTTON0), &GUI_Font32_ASCII);
    //
    //GUI_ID_BUTTON1
    //
    BUTTON_SetFont(WM_GetDialogItem(hWin, GUI_ID_BUTTON1), &GUI_Font32_ASCII);
    //
    //GUI_ID_BUTTON2
    //
    BUTTON_SetFont(WM_GetDialogItem(hWin, GUI_ID_BUTTON2), &GUI_Font32_ASCII);
}

/*********************************************************************
*
*       Dialog callback routine
*/
static void _cbCallback(WM_MESSAGE *pMsg)
{
    int NCode, Id;
    WM_HWIN hWin = pMsg->hWin;
    //printf("homepage touched\n");
    switch (pMsg->MsgId)
    {
    case WM_PAINT:
        PaintDialog(pMsg);
        break;
    case WM_INIT_DIALOG:
        InitDialog(pMsg);
        break;
    case WM_KEY:
        switch (((WM_KEY_INFO *)(pMsg->Data.p))->Key)
        {
        case GUI_KEY_ESCAPE:
            GUI_EndDialog(hWin, 1);
            break;
        case GUI_KEY_ENTER:
            GUI_EndDialog(hWin, 0);
            break;
        }
        break;
    case WM_NOTIFY_PARENT:
        Id = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        switch (Id)
        {
        case GUI_ID_OK:
            if (NCode == WM_NOTIFICATION_RELEASED)
                GUI_EndDialog(hWin, 0);
            break;
        case GUI_ID_CANCEL:
            if (NCode == WM_NOTIFICATION_RELEASED)
                GUI_EndDialog(hWin, 0);
            break;
        case GUI_ID_BUTTON0:
            switch (NCode)
            {
            case WM_NOTIFICATION_CLICKED:
                OnOscillClicked(pMsg);
                break;
            }
            break;
        case GUI_ID_BUTTON1:
            switch (NCode)
            {
            case WM_NOTIFICATION_CLICKED:
                OnMultiMeterClicked(pMsg);
                break;
            }
            break;
        }
        break;
    default:
        WM_DefaultProc(pMsg);
    }
}

/*********************************************************************
*
*       MainTask
*
**********************************************************************
*/
GUI_HWIN di;
/**
 * @brief : 绘制主界面
 * @param {*}
 * @return {*}
 */
void createHomePage(void)
{
    WM_SetDesktopColor(GUI_WHITE);   /* Automacally update desktop window */
    WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */
    di = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
}

void onViewBackToMainPage(WM_MESSAGE *lastWinMsg)
{
}
/**
 * @brief : 显示提示信息
 * @param {char} *info
 * @param {uint8_t} sec
 * @return {*}
 */
void onViewShowToastInfo(char *info, uint8_t sec)
{
    //GUI_MessageBox(info,"Information",0);

    // GUI_Delay(500);
}
void closeHomePage(void)
{
    GUI_EndDialog(di, 0);
}
#endif